//
//  KTCoinDetailSinglePankouView.swift
//  KOLToken
//
//  Created by san.yang on 2020/3/10.
//  Copyright © 2020 iOS-team. All rights reserved.
//

import UIKit
import DynamicColor
class KTCoinDetailSinglePankouView: UIView {
    
    // MARK: - private
    private let kKTCoinDetailCollectionViewCell = "kKTCoinDetailCollectionViewCell"

    // MARK: - init
    override init(frame: CGRect) {
        super.init(frame: frame)
        buildUI()
    }
    
    private func buildUI() {
        backgroundColor = .white
        addSubview(name)
        addSubview(dollar)
        addSubview(RMB)
        addSubview(zdf)
        addSubview(inflowTitle)
        addSubview(inflowValue)
        addSubview(pankouView)
        pankouView.register(KTCoinDetailCollectionViewCell.self, forCellWithReuseIdentifier: "kKTCoinDetailCollectionViewCell")
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override func layoutSubviews() {
        super.layoutSubviews()
        
        let leftSpaceing = 10
        let topSpaceing = 16
        let middleSpaceing = 16
        
        name.snp.makeConstraints { (make) in
            make.left.equalTo(leftSpaceing)
            make.top.equalTo(topSpaceing)
            make.height.equalTo(14)
        }
        
        dollar.snp.makeConstraints { (make) in
            make.left.equalTo(name)
            make.top.equalTo(name.snp_bottom).offset(middleSpaceing)
            make.height.equalTo(20)
        }
        
        RMB.snp.makeConstraints { (make) in
            make.left.equalTo(name)
            make.top.equalTo(dollar.snp_bottom).offset(middleSpaceing)
            make.height.equalTo(14)
        }
        
        zdf.snp.makeConstraints { (make) in
            make.left.equalTo(RMB.snp_right).offset(18)
            make.top.height.equalTo(RMB)
        }
        
        inflowTitle.snp.makeConstraints { (make) in
            make.left.equalTo(name)
            make.top.equalTo(zdf.snp_bottom).offset(middleSpaceing)
            make.width.equalTo(40)
            make.height.equalTo(16)
        }

        inflowValue.snp.makeConstraints { (make) in
            make.left.equalTo(inflowTitle.snp_right).offset(18)
            make.top.height.equalTo(inflowTitle)
        }

        pankouView.snp.makeConstraints { (make) in
            make.width.equalTo(210)
            make.right.equalTo(-leftSpaceing)
            make.top.equalTo(dollar)
            make.height.equalTo(90)
        }
    }
    
    // MARK: - lazy
    
    lazy var name: UILabel = {
        let label = FastLabel().fastCreateLabel(text: "QRL", color: nil, alignment: .left, textColor: .black, font: UIFont.systemFont(ofSize: 16))
        return label
    }()
    
    lazy var dollar: UILabel = {
        let label = FastLabel().fastCreateLabel(text: "$0.00002", color: nil, alignment: .left, textColor: .black, font: UIFont.systemFont(ofSize: 16))
        return label
    }()
    
    lazy var RMB: UILabel = {
        let label = FastLabel().fastCreateLabel(text: "0.1098", color: nil, alignment: .left, textColor: .black, font: UIFont.systemFont(ofSize: 16))
        return label
    }()
    
    lazy var zdf: UILabel = {
        let label = FastLabel().fastCreateLabel(text: "+10.0%", color: nil, alignment: .left, textColor: .black, font: UIFont.systemFont(ofSize: 16))
        return label
    }()
    
    lazy var inflowTitle: UILabel = {
        let label = FastLabel().fastCreateLabel(text: "净流入", color: nil, alignment: .left, textColor: .black, font: UIFont.systemFont(ofSize: 16))
        return label
    }()
    
    lazy var inflowValue: UILabel = {
        let label = FastLabel().fastCreateLabel(text: "$3,327.8", color: nil, alignment: .left, textColor: .black, font: UIFont.systemFont(ofSize: 16))
        return label
    }()
    
    lazy var pankouView: UICollectionView = {
        let layout = UICollectionViewFlowLayout.init()
        layout.itemSize = CGSize(width: 100, height: 30)
        layout.minimumLineSpacing = 0
        layout.minimumInteritemSpacing = 10
        let collectionView = UICollectionView.init(frame: .zero, collectionViewLayout: layout)
        collectionView.delegate = self
        collectionView.dataSource = self
        collectionView.backgroundColor = .clear
        return collectionView
    }()
}

extension KTCoinDetailSinglePankouView: UICollectionViewDelegate, UICollectionViewDataSource {
    func numberOfSections(in collectionView: UICollectionView) -> Int {
        return 1
    }

    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 6
    }

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell:KTCoinDetailCollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: kKTCoinDetailCollectionViewCell, for: indexPath) as! KTCoinDetailCollectionViewCell
        return cell
    }
}

